<?php

namespace backend\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\form\BrandForm;

/**
 * BrandSearch represents the model behind the search form about `backend\models\Brand`.
 */
class BrandSearch extends BrandForm implements \backend\models\search\SearchInterface
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
          [['brand_id'], 'integer'],
          [['brand_name', 'brand_logo', 'brand_msg', 'brand_manager', 'brand_account', 'created_at', 'updated_at'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return
          [
            'brand_id'      => Yii::t('app', 'Brand ID'),
            'brand_name'    => Yii::t('app', 'Brand Name'),
            'brand_logo'    => Yii::t('app', 'Brand Logo'),
            'brand_msg'     => Yii::t('app', 'Brand Msg'),
            'brand_manager' => Yii::t('app', 'Brand Manager'),
            'brand_account' => Yii::t('app', 'Brand Account'),
            'created_at'    => Yii::t('app', 'Created At'),
            'updated_at'    => Yii::t('app', 'Updated At'),
          ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search(array $params = [], array $options = [])
    {
        $query = BrandForm::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
          'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
          'brand_id' => $this->brand_id,
          'created_at' => $this->created_at,
          'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'brand_name', $this->brand_name])
          ->andFilterWhere(['like', 'brand_logo', $this->brand_logo])
          ->andFilterWhere(['like', 'brand_msg', $this->brand_msg])
          ->andFilterWhere(['like', 'brand_manager', $this->brand_manager])
          ->andFilterWhere(['like', 'brand_account', $this->brand_account]);

        return $dataProvider;
    }
}